package com.briup.ch10;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/11
 * @Description:
 */
public class Test06 {
    public static void main(String[] args) {
        Runnable r=new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread()+" "+Thread.currentThread().getState());
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    //e.printStackTrace();
                    System.out.println(e.getMessage());
                }
            }
        };
        ThreadGroup group=new ThreadGroup("线程组");
        Thread t1=new Thread(group,r,"t1");
        Thread t2=new Thread(group,r,"t2");
        Thread t3=new Thread(group,r,"t3");
        System.out.println("t1的状态:"+t1.getState());
        //启动之前做设置
        t1.start();
        t2.start();
        t3.start();
        System.out.println("t1的状态:"+t1.getState());
        int size=group.activeCount();//活动的线程，所以一定要在启动之后
        Thread[] arr=new Thread[size];
        group.enumerate(arr);
        for (int i = 0; i < size; i++) {
            System.out.println(arr[i].getName());
            arr[i].interrupt();
        }
        System.out.println(size);
        try {
            Thread.sleep(200);//睡眠时间大于线程的执行完毕时间，下面就是true，否则是false
        } catch (InterruptedException e) {
            e.printStackTrace();

        }
        group.destroy();
        System.out.println(group.isDestroyed());
        System.out.println("t1的状态:"+t1.getState());
    }
}
